﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace ValidationFramework
{
    public class RuleFactory
    {
        public static PropertyStateRule CreatePropertyStateRule(PropertyInfo info, PropertyStateRuleAttributeBase attrib)
        {
            return new PropertyStateRule(attrib.CreateValidator())
            {
                ErrorMessage = attrib.ErrorMessage,
                PropertyName = info.Name,
                UseErrorProvider = attrib.UseErrorMessageProvider
            };
        }
        public static PropertyValueRule CreatePropertyValueRule(PropertyInfo info, PropertyValueRuleAttributeBase attrib)
        {
            return new PropertyValueRule(attrib.CreateValidator())
            {
                ErrorMessage = attrib.ErrorMessage,
				PropertyName = info.Name,
                UseErrorProvider = attrib.UseErrorMessageProvider
            };
        }
        public static ParameterRule CreateParameterRule(ParameterRuleAttributeBase attrib)
        {
            return new ParameterRule(attrib.CreateValidator())
            {
                ErrorMessage = attrib.ErrorMessage,
                UseErrorProvider = attrib.UseErrorMessageProvider
            };
        }
    }
}
